"""
    __init__.py
    ~~~~~~~~
    配置项

    :author: Fufu, 2019/9/2
"""
import os

from flask import current_app, json
from loguru import logger


def get_conf_json(path, file):
    """
    通用: 获取 JSON 配置文件

    :param path: 相对于 conf, e.g. bgp
    :param file: 文件名, 不带扩展名, e.g. as-name
    :return: dict，e.g. {'123': '成都'}
    """
    ret = {}
    file = os.path.join(current_app.root_path, 'conf', path, file + '.json')

    try:
        with open(file, 'r', encoding='utf-8') as f:
            ret = json.load(f)
    except Exception as e:
        logger.error('{0!r} {1}'.format(e, file))

    return ret


# conda
# virtualenv
# pipenv